/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.grt192.controller.breakaway.teleop;

import com.grt192.core.EventController;
import com.grt192.event.SensorEvent;
import com.grt192.event.component.ButtonListener;
import com.grt192.mechanism.GRTDriverStation;
import com.grt192.mechanism.breakaway.Roller;
import com.grt192.sensor.GRTJoystick;

/**
 *
 * @author Vikram
 */
public class RollerController extends EventController implements ButtonListener {

    private boolean running;
    private Roller rollers;

    public RollerController(GRTDriverStation dStation, Roller rollers) {
        super();
        addMechanism("DriverStation", dStation);
        addMechanism("Rollers", rollers);
        running = false;
        this.rollers = (Roller) getMechanism("Rollers");
        ((GRTJoystick) dStation.getSensor("leftJoystick")).addButtonListener(this);
        ((GRTJoystick) dStation.getSensor("rightJoystick")).addButtonListener(this);
    }

    public void buttonUp(SensorEvent e, String key) {
        String joyStick = e.getSource().getId();
        if (key.equals("Button1")) {
            if (joyStick.equals("left")) {
                rollers.stopLeftRoller();
                rollers.stopRightRoller();
                running = false;
            }
            if (joyStick.equals("right")) {
                if(running) {
                    rollers.leftGrab();
                    rollers.rightGrab();
                }
            }
        }
    }

    public void buttonDown(SensorEvent e, String key) {
        if (key.equals("Button1")) {
            String joyStick = e.getSource().getId();
            if (joyStick.equals("left")) {
                rollers.leftGrab();
                rollers.rightGrab();
                running = true;
            }
            if (joyStick.equals("right")) {
                if(running) {
                    rollers.leftPush();
                    rollers.rightPush();
                }

            }
        }

    }
}
